from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time
# import logging
# logging.basicConfig(level=logging.DEBUG)

# 初始化浏览器驱动
driver = webdriver.Chrome(ChromeDriverManager().install())
# 设置浏览器最大化
driver.maximize_window()
# 打开百度首页
driver.get("https://www.baidu.com")
time.sleep(3)

# # 定位输入框元素
# input_element = driver.find_element(By.CSS_SELECTOR, "#kw")
# # input_element = driver.find_element('css selector', "#kw")
# # 输入坚果
# input_element.send_keys("坚果")
# # driver.find_element(By.CSS_SELECTOR, "#kw").send_keys("坚果")
# time.sleep(2)
# # 清空输入框
# input_element.clear()
# # 定位百度一下元素
# baidu_button = driver.find_element(By.XPATH, "//input[@id='su']")
# # baidu_button = driver.find_element('xpath', "//input[@id='su']")
# # 点击-百度一下
# baidu_button.click()
# driver.find_element(By.ID, "su").click()

# # 定位一组元素
# elements = driver.find_elements(By.XPATH, "//a[starts-with(@class, 'title-content')]")
# # print(elements)
# for ele in elements:
#     ele.click()
#     time.sleep(3)

# # 定位表单元素直接提交
# driver.find_element(By.CSS_SELECTOR, "form").submit()
time.sleep(30)
# 定位【设置】按钮
setting_button = driver.find_element(By.ID, "s-usersetting-top")
# 获取元素文本值
print(setting_button.text)
# 获取元素属性值，如果属性值不存在，返回none
print("id属性值为：", setting_button.get_attribute("id"))
print("class属性值为：", setting_button.get_attribute("class"))
print("name属性值为：", setting_button.get_attribute("name"))
print("target属性值为：", setting_button.get_attribute("target"))
# 获取元素尺寸
print("当前元素尺寸为：", setting_button.size)
# 获取元素是否可见
print(setting_button.is_displayed())
# 关闭浏览器
time.sleep(3)
driver.quit()